package com.zcsy.manage.owner.controller.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zcsy.commons.constants.OwnerConstants;
import com.zcsy.commons.model.RequestJson;
import com.zcsy.manage.model.system.App;
import com.zcsy.manage.service.system.IAppService;

/**
 * @Title: AppController.java
 * @Package： com.zcsy.manage.owner.controller.system;
 * @Description: 版本控制层
 * @author yangfan 373188993@qq.com
 * @Copyright: 2015 武汉中财数元信息技术有限公司 All rights reserved.
 * @date 2016年7月15日
 * @version 1.0
 * @see JDK1.7.0_75
 * @since
 */
@Controller
@RequestMapping(value = "/app")
public class AppController {
	
	@Autowired
	private IAppService appService;
	
	/**
	 * @Description 根据客户端类型查询版本信息
	 * @param type 客户端类型
	 * @param req 用户请求
	 * @return 用户响应
	 * @author yangfan 373188993@qq.com
	 * @date 2016年7月15日
	 * @see 
	 */
	@RequestMapping(value = "getAppInfo")
	@ResponseBody
	public RequestJson getAppInfo(Integer type) {

		RequestJson result = new RequestJson();
		
		try {
		    if(null != type){
		        App app = appService.getAppInfoByType(type);
		        
		        //判断客户端类型是否存在
		        if(app != null){
		            result.setObj(app);
		            result.setSuccess(true);
		            result.setResultCode(OwnerConstants.REQUEST_SUCCESS);
		            
		        } else {
		            result.setMsg("该类型的客户端不存在！");
		            result.setSuccess(false);
		            result.setResultCode(OwnerConstants.APP_NOT_EXIST);
		        }
		        
		    } else {
		        result.setMsg("客户端类型不能为空！");
		        result.setSuccess(false);
		        result.setResultCode(OwnerConstants.APP_TYPE_NULL);
		    }
        } catch (Exception e) {
            result.setSuccess(false);
            result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
            result.setMsg("网络异常");
        }
		
		return result;
	}
	
}
   
